<template>
  <div class="login-modal" :class="{ 'dark': isDarkMode }" v-if="$store.state.loginVisible" @click.self="handleClose">
    <div class="login-wrapper" :class="{ 'shake-animation': errorMsg }">
      <div class="login-decoration">
        <div class="decoration-circle"></div>
        <div class="decoration-circle"></div>
        <div class="decoration-circle"></div>
      </div>

      <div class="login-header">
        <h3>{{ formTitles[currentForm] }}</h3>
        <p class="subtitle">{{ formSubtitles[currentForm] }}</p>
        <span class="close" @click="handleClose">×</span>
      </div>

        <!-- 登录表单 -->
      <div class="login-body">
        <div v-show="currentForm === 'login'" class="form-container">
          <form @submit.prevent="handleLogin">
            <div class="form-item">
            <div class="input-wrapper">
              <i class="fas fa-user"></i>
              <input 
                type="text" 
                required
                v-model="loginForm.username" 
                placeholder="请输入用户名"
                @keyup.enter="handleLogin"
              >
            </div>
          </div>
          <div class="form-item">
            <div class="input-wrapper">
              <i class="fas fa-lock"></i>
              <input 
                :type="showPassword ? 'text' : 'password'"
                required
                v-model="loginForm.password" 
                placeholder="请输入密码"
                @keyup.enter="handleLogin"
              >
              <i 
                :class="['password-toggle', 'fas', showPassword ? 'fa-eye' : 'fa-eye-slash']"
                @click="showPassword = !showPassword"
              ></i>
            </div>
          </div>

          <div class="form-options">
            <a class="forgot-password" @click="switchForm('forgot')">忘记密码？</a>
          </div>
          
          <div class="form-item">
            <button 
              class="submit-btn ripple" 
              :disabled="loading"
            >
              <span v-if="!loading">登 录</span>
              <span v-else class="loading-spinner"></span>
            </button>
          </div>
          </form>
        

          <div class="divider">
            <span>其他登录方式</span>
          </div>

          <div class="third-party-login">
            <div 
              v-for="(item, type) in loginTypes" 
              :key="type"
              class="login-icon-wrapper"
              @click="handleThirdPartyLogin(type)"
            >
              <div :class="['login-icon', type]">
                <mj-tooltip :content="item.title" >
                  <i class="fab fa-github" v-if="type === 'github'" ></i>
                </mj-tooltip>

                <mj-tooltip :content="item.title"  >
                  <i class="fab fa-qq" v-if="type === 'qq'" ></i>
                </mj-tooltip>

                <mj-tooltip :content="item.title"  >
                  <i class="fab fa-weixin"  v-if="type === 'wechat'" ></i>
                </mj-tooltip>

                <mj-tooltip :content="item.title"  >
                  <i class="fab fa-git-alt"  v-if="type === 'gitee'" ></i>
                </mj-tooltip>
              </div>
              <span class="tooltip-text">{{ item.title }}</span>
            </div>
          </div>

          <div class="form-switch">
            还没有账号？<a @click="switchForm('register')">立即注册</a>
          </div>
        </div>

        <!-- 注册表单 -->
        <div v-show="currentForm === 'register'" class="form-container">
          <form @submit.prevent="handleRegister">
            <div class="form-item">
            <div class="input-wrapper">
              <i class="fas fa-user"></i>
              <input 
                type="text" 
                required
                v-model="registerForm.nickname" 
                placeholder="请输入用户名"
              >
            </div>
          </div>
          <div class="form-item verification-code">
            <div class="input-wrapper">
              <i class="fas fa-envelope"></i>
              <input 
                type="email" 
                required
                v-model="registerForm.email" 
                placeholder="请输入邮箱"
              >
            </div>
          </div>
          <div class="form-item verification-code">
            <div class="input-wrapper">
              <i class="fas fa-key"></i>
              <input 
                type="text" 
                required
                v-model="registerForm.code" 
                placeholder="请输入验证码"
              >
            </div>
            <button 
              class="code-btn"
              @click="sendRegisterCode"
              :disabled="codeSending"
            >
              {{ codeButtonText }}
            </button>
          </div>
          <div class="form-item">
            <div class="input-wrapper">
              <i class="fas fa-lock"></i>
              <input 
                :type="showPassword ? 'text' : 'password'"
                required
                v-model="registerForm.password" 
                placeholder="请输入密码"
              >
              <i 
                :class="['password-toggle', 'fas', showPassword ? 'fa-eye' : 'fa-eye-slash']"
                @click="showPassword = !showPassword"
              ></i>
            </div>
          </div>

          <div class="form-item">
            <button 
              class="submit-btn ripple" 
              :disabled="loading"
            >
              <span v-if="!loading">注 册</span>
              <span v-else class="loading-spinner"></span>
            </button>
          </div>

          <div class="form-switch">
            已有账号？<a @click="switchForm('login')">立即登录</a>
          </div>
          </form>
        
        </div>

        <!-- 忘记密码表单 -->
        <div v-show="currentForm === 'forgot'" class="form-container">

          <form @submit.prevent="handleResetPassword">
            <div class="form-item">
            <div class="input-wrapper">
              <i class="fas fa-envelope"></i>
              <input 
                type="email" 
                required
                v-model="forgotForm.email" 
                placeholder="请输入注册邮箱"
              >
            </div>
          </div>

          <div class="form-item verification-code">
            <div class="input-wrapper">
              <i class="fas fa-key"></i>
              <input 
                type="text" 
                required
                v-model="forgotForm.code" 
                placeholder="请输入验证码"
              >
            </div>
            <button 
              class="code-btn"
              @click="sendVerificationCode"
              :disabled="codeSending"
            >
            {{ codeButtonText }}
            </button>
          </div>

          <div class="form-item">
            <div class="input-wrapper">
              <i class="fas fa-lock"></i>
              <input 
                :type="showPassword ? 'text' : 'password'"
                required
                v-model="forgotForm.password" 
                placeholder="请输入新密码"
              >
              <i 
                :class="['password-toggle', 'fas', showPassword ? 'fa-eye' : 'fa-eye-slash']"
                @click="showPassword = !showPassword"
              ></i>
            </div>
          </div>
          <div class="form-item">
            <button 
              class="submit-btn ripple" 
              :disabled="loading"
            >
              <span v-if="!loading">重置密码</span>
              <span v-else class="loading-spinner"></span>
            </button>
          </div>

          <div class="form-switch">
            <a @click="switchForm('login')">返回登录</a>
          </div>
          </form>
          
        </div>
      </div>

      <!-- 微信二维码弹窗 -->
      <div class="qrcode-modal" v-if="wechatForm.showQrcode" @click.self="handleCloseWechat">
        <div class="qrcode-container">
          <div class="qrcode-header">
            <span>微信扫码登录</span>
            <span class="close-qrcode" @click="wechatForm.showQrcode = false">×</span>
          </div>
          <div class="qrcode-content">
            <div class="qrcode-box">
              <!-- 这里放二维码图片 -->
              <img src="https://img.shiyit.com/wechatQr.jpg" alt="微信二维码">
            </div>
            <p class="qrcode-tip">登录验证码：
              <span class="code-text">{{ wechatForm.code }}</span>
              <span class="code-text" v-if="wechatForm.code === '验证码已失效'">
                <i class="fas fa-sync-alt" @click="getWechatLoginCode"></i>
              </span>
            </p>
            <p class="qrcode-tip">微信扫码关注公众号，并发送验证码</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { disableScroll,enableScroll } from '@/utils/scroll'
import { sendEmailCodeApi,registerApi,forgotPasswordApi,
  getWechatLoginCodeApi,getWechatIsLoginApi,getAuthRenderApi } from '@/api/auth'
export default {
  name: 'Login',
  data() {
    return {
      currentForm: 'login',
      showPassword: false,
      rememberMe: false,
      loading: false,
      errorMsg: '',
      wechatForm: {
        code: '',
        showQrcode: false,
      },
      countdown: 0,
      formTitles: {
        login: '欢迎回来',
        register: '创建账号',
        forgot: '重置密码'
      },
      formSubtitles: {
        login: '登录您的账号继续访问',
        register: '填写信息创建您的账号',
        forgot: '通过邮箱重置您的密码'
      },
      loginForm: {
        username: '',
        password: '',
        source: 'PC'
      },
      registerForm: {
        nickname: '',
        email: '',
        password: '',
        code: ''
      },
      forgotForm: {
        email: '',
        code: '',
        password: ''
      },
      loginTypes: {
        github: {
          title: 'GitHub账号登录',
          icon: 'fab fa-github'
        },
        qq: {
          title: 'QQ账号登录',
          icon: 'fab fa-qq'
        },
        wechat: {
          title: '微信扫码登录',
          icon: 'fab fa-weixin'
        },
        gitee: {
          title: '码云账号登录',
          icon: 'fab fa-git-alt'
        }
      },
      isDarkMode: window.matchMedia('(prefers-color-scheme: dark)').matches,
      codeSending: false,
      codeButtonText: '发送验证码',
      codeTimer: null,
      pollingTimer: null,
    }
  },
  watch: {
    '$store.state.loginVisible': {
      handler(newVal) {
        if (newVal) {
          disableScroll()
          Object.keys(this.loginTypes).forEach(key => {
            if(!this.$store.state.webSiteInfo.loginTypeList.includes(key)){
              delete this.loginTypes[key]
            }
          })
        } else {
          enableScroll()
        }
      },
      immediate: true
    }
  },
  mounted() {
    // 监听系统主题变化
    window.matchMedia('(prefers-color-scheme: dark)')
      .addEventListener('change', e => {
        this.isDarkMode = e.matches
      })
  },
  methods: {
    /**
     * 
     * @param form 
     */
    switchForm(form) {
      this.currentForm = form
      this.errorMsg = ''
      this.loading = false
    },
    /**
     * 关闭登录弹窗
     */
    handleClose() {
      this.$store.commit('SET_LOGIN_VISIBLE', false)
      this.resetForm()
      this.clearTimer()
    },
    /**
     * 重置表单
     */
    resetForm() {
      this.errorMsg = ''
      this.currentForm = 'login'
      this.wechatForm.showQrcode = false
      this.wechatForm.code = ''
      this.loginForm = { nickname: '', password: '' ,source: 'PC'}
      this.registerForm = { nickname: '', email: '', password: '',  code: '' }
      this.forgotForm = { email: '', code: '', password: '' }
    },
    /**
     * 登录
     */
    async handleLogin() {
      
      this.loading = true
      try {
        await this.$store.dispatch('loginAction', this.loginForm)
        this.$message.success('登录成功')
        this.handleClose()
      } catch (error) {
        this.$message.error(error.message || '登录失败，请重试')
      } finally {
        this.loading = false
      }
    },
    /**
     * 注册
     */
    async handleRegister() {
      if (!this.registerForm.nickname || !this.registerForm.email || 
          !this.registerForm.password|| !this.registerForm.code) {
        this.errorMsg = '请填写完整注册信息'
        return
      }
      
      this.loading = true
      this.errorMsg = ''
      
      try {
        await registerApi(this.registerForm)
        this.$message.success('注册成功')
        this.switchForm('login')
      } catch (error) {
        this.$message.error(error.message || '注册失败，请重试')
      } finally {
        this.loading = false
      }
    },
    /**
     * 忘记密码
     */
    async handleResetPassword() {
      this.loading = true
      
      try {
        // 调用重置密码接口
        await forgotPasswordApi(this.forgotForm)
        this.$message.success('密码重置成功')
        this.switchForm('login')
      } catch (error) {
        this.$message.error(error.message || '重置失败，请重试')
      } finally {
        this.loading = false
      }
    },
    /**
     * 发送忘记密码邮箱验证码
     */
    async sendVerificationCode() {
      if (this.codeSending) return
      
      if (!this.forgotForm.email) {
        this.$message.error('请先输入邮箱')
        return
      }
      
      this.codeSending = true
      this.sendEmailCode(this.forgotForm.email)
   
    },

    /**
     * 第三方登录
     */
    handleThirdPartyLogin(type) {
      if (type === 'wechat') {
        this.wechatForm.showQrcode = true
        this.getWechatLoginCode()
        return
      }
      getAuthRenderApi(type).then(res => {
        window.open(res.data,"_self")
      })
    },
    /**
     * 关闭微信二维码弹窗
     */
    handleCloseWechat() {
      this.wechatForm.showQrcode = false
      this.wechatForm.code = ''
      this.clearTimer()
    },

    /**
     * 获取微信登录验证码
     */
    getWechatLoginCode() {
      getWechatLoginCodeApi().then(res => {
          this.wechatForm.code = res.data
          this.pollingWechatIsLogin()
          // 开始倒计时
          let countdown = 60
          this.codeTimer = setInterval(() => {
            countdown--
            if (countdown <= 0) {
              clearInterval(this.codeTimer)
              clearInterval(this.pollingTimer)
              this.wechatForm.code = '验证码已失效'
            }
          }, 1000)
        })
    },
    /**
     * 定时轮询获取微信登录状态
     */
    pollingWechatIsLogin() {
      this.pollingTimer = setInterval(() => {
        getWechatIsLoginApi(this.wechatForm.code).then(res => {
          if(res.code === 200) {
            this.$store.commit('SET_TOKEN', res.data.token)
            this.$store.commit('SET_USER_INFO', res.data)
            clearInterval(this.pollingTimer)
            this.$message.success('登录成功')
            this.handleClose()
          }
        })
      }, 1000)
    },
  

    /**
     * 发送邮箱验证码
     */
    sendRegisterCode() {
      if (this.codeSending) return
      
      if (!this.registerForm.email) {
        this.$message.error('请先输入邮箱')
        return
      }
      this.codeSending = true
      this.sendEmailCode(this.registerForm.email)
    },

    /**
     * 发送邮箱验证码
     */
    sendEmailCode(email) {
      sendEmailCodeApi(email).then(res =>{
        this.$message.success("发送成功，请前往邮箱查看验证码")
        // 开始倒计时
        let countdown = 60
        this.codeButtonText = `${countdown}秒后重试`
        
        this.codeTimer = setInterval(() => {
          countdown--
          if (countdown <= 0) {
            clearInterval(this.codeTimer)
            this.codeSending = false
            this.codeButtonText = '发送验证码'
          } else {
            this.codeButtonText = `${countdown}秒后重试`
          }
        }, 1000)
      }).catch(err => {
        this.$message.error(err.message || "发送失败")
        this.codeSending = false
      })
    },

    /**
     * 清理定时器
     */
    clearTimer() {
      if (this.codeTimer) {
        clearInterval(this.codeTimer)
      }
      if (this.pollingTimer) {
        clearInterval(this.pollingTimer)
      }
    }
  
  },
  beforeDestroy() {
    this.clearTimer()
  }
}
</script>
<style scoped>
.login-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(17, 24, 39, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(8px);
  animation: fadeIn 0.3s ease;
}

.login-wrapper {
  background: rgba(255, 255, 255, 0.98);
  width: 400px;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  transform: translateY(0);
  transition: transform 0.3s ease;
}


.shake-animation {
  animation: shake 0.5s ease-in-out;
}

.login-header {
  padding: 35px 24px;
  text-align: center;
  position: relative;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
}

.login-header h3 {
  margin: 0;
  font-size: 24px;
  letter-spacing: -0.5px;
  color: #fff;
  font-weight: 500;
}

.close {
  position: absolute;
  right: 20px;
  top: 20px;
  cursor: pointer;
  font-size: 24px;
  color: rgba(255, 255, 255, 0.8);
  transition: all 0.3s;
}

.close:hover {
  transform: rotate(90deg);
  color: #fff;
}

.login-body {
  padding: 30px;
  background: var(--card-bg);
}

.welcome-text {
  text-align: center;
  color: #666;
  margin-bottom: 25px;
  font-size: 14px;
}

.input-wrapper {
  position: relative;
  margin-bottom: 20px;
}

.input-wrapper i:not(.password-toggle) {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #6b7280;
  font-size: 16px;
}

.input-wrapper input {
  width: 100%;
  padding: 14px 45px;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  font-size: 15px;
  transition: all 0.2s ease;
  background: rgba(249, 250, 251, 0.9);
}

.input-wrapper input:focus {
  background: #fff;
  border-color: #4f46e5;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
  outline: none;
}

.login-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: #fff;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.login-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.3);
}

.login-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 1s linear infinite;
}

.divider {
  position: relative;
  text-align: center;
  margin: 30px 0;
}

.divider::before,
.divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: #e5e7eb;
}

.divider::before {
  left: 0;
}

.divider::after {
  right: 0;
}

.divider span {
  background: #fff;
  padding: 0 15px;
  color: #6b7280;
  font-size: 14px;
}

.third-party-login {
  display: flex;
  justify-content: center;
  gap: 25px;
  margin-top: 25px;
}

.login-icon-wrapper {
  position: relative;
}

.login-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: #f3f4f6;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 20px;
}

.login-icon:hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.github {
  color: #24292e;
}

.github:hover {
  background: #24292e;
  color: #fff;
}

.qq {
  color: #12B7F5;
}

.qq:hover {
  background: #12B7F5;
  color: #fff;
}

.wechat {
  color: #07C160;
}

.wechat:hover {
  background: #07C160;
  color: #fff;
}

.gitee {
  color: #C71D23;
}

.gitee:hover {
  background: #C71D23;
  color: #fff;
}

.ripple {
  position: relative;
  overflow: hidden;
}

.ripple:after {
  content: "";
  display: block;
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  pointer-events: none;
  background-image: radial-gradient(circle, #fff 10%, transparent 10.01%);
  background-repeat: no-repeat;
  background-position: 50%;
  transform: scale(10, 10);
  opacity: 0;
  transition: transform .5s, opacity 1s;
}

.ripple:active:after {
  transform: scale(0, 0);
  opacity: .3;
  transition: 0s;
}

.login-decoration {
  position: absolute;
  top: 10px;
  left: 20px;
  display: flex;
  gap: 8px;
}

.decoration-circle {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.decoration-circle:nth-child(1) { background: #ff5f57; }
.decoration-circle:nth-child(2) { background: #ffbd2e; }
.decoration-circle:nth-child(3) { background: #28c940; }

.login-header {
  padding: 30px 24px;
  text-align: center;
  position: relative;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
}

.subtitle {
  margin: 8px 0 0;
  color: rgba(255, 255, 255, 0.8);
  font-size: 14px;
}

.input-wrapper {
  position: relative;
  margin-bottom: 20px;
}

.password-toggle {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  color: #6b7280;
  transition: color 0.3s;
  font-size: 16px;
}

.password-toggle:hover {
  color: #666;
}

.form-options {
  display: flex;
  justify-content:flex-end;
  align-items: center;
  margin-bottom: 20px;
}


.forgot-password {
  font-size: 13px;
  color: #6366f1;
  text-decoration: none;
  transition: color 0.3s;
  cursor: pointer;
}

.forgot-password:hover {
  color: #4f46e5;
}

.qrcode-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1100;
}

.qrcode-container {
  background: #fff;
  width: 300px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.qrcode-header {
  padding: 15px 20px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8f9fa;
}

.close-qrcode {
  cursor: pointer;
  font-size: 20px;
  color: #999;
  transition: color 0.3s;
}

.close-qrcode:hover {
  color: #666;
}

.qrcode-content {
  padding: 20px;
  text-align: center;
}

.qrcode-box {
  width: 200px;
  height: 200px;
  margin: 0 auto;
  background: #f5f5f5;
  border: 1px solid #eee;
  border-radius: 4px;
  img{
    width: 100%;
    height: 100%;
  }
}

.qrcode-tip {
  margin-top: 15px;
  color: #666;
  font-size: 14px;
  i{
    cursor: pointer;
    color: #b71828;
    font-size: 12px;
  }
}

.code-text{
  color: #6366f1;
  font-weight: 600;
  margin-right: 5px;
}

.tooltip {
  position: relative;
}

.tooltip-text {
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s;
}

.tooltip:hover .tooltip-text {
  opacity: 1;
  visibility: visible;
}

.register-tip {
  text-align: center;
  margin-top: 20px;
  font-size: 13px;
  color: #666;
}

.register-link {
  color: #6366f1;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.3s;
}

.register-link:hover {
  color: #4f46e5;
}

.form-container {
  animation: fadeIn 0.3s ease;
}

.verification-code {
  display: flex;
  gap: 10px;
}

.code-btn {
  padding: 0 15px;
  height: 42px;
  border: none;
  border-radius: 8px;
  background: #6366f1;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s;
  white-space: nowrap;
}

.code-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.form-switch {
  text-align: center;
  margin-top: 25px;
  font-size: 14px;
  color: #666;
}

.form-switch a {
  color: #6366f1;
  text-decoration: none;
  cursor: pointer;
  margin-left: 5px;
  transition: color 0.3s;
}

.form-switch a:hover {
  color: #4f46e5;
}

.submit-btn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  color: #fff;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  cursor: pointer;
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
}

.submit-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes shake {
  0%, 100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.form-container {
  animation: slideUp 0.3s ease;
}

/* 深色模式样式 */
.dark .login-wrapper {
  background: rgba(31, 41, 55, 0.98);
  color: #e5e7eb;
}

.dark .login-header {
  background: linear-gradient(135deg, #4338ca 0%, #6d28d9 100%);
}

.dark .input-wrapper input {
  background: rgba(17, 24, 39, 0.8);
  border-color: #374151;
  color: #e5e7eb;
}

.dark .input-wrapper input:focus {
  background: rgba(17, 24, 39, 0.95);
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.dark .input-wrapper input::placeholder {
  color: #6b7280;
}

.dark .input-wrapper i {
  color: #9ca3af;
}

.dark .divider::before,
.dark .divider::after {
  background: #374151;
}

.dark .divider span {
  background: rgba(31, 41, 55, 0.98);
  color: #9ca3af;
}

.dark .login-icon {
  background: rgba(17, 24, 39, 0.8);
}

.dark .error-msg {
  background: rgba(220, 38, 38, 0.1);
  border-color: rgba(220, 38, 38, 0.2);
}

.dark .form-switch {
  color: #9ca3af;
}

.dark .form-switch a {
  color: #818cf8;
}

.dark .form-switch a:hover {
  color: #6366f1;
}

.dark .forgot-password {
  color: #818cf8;
}

.dark .forgot-password:hover {
  color: #6366f1;
}

.dark .qrcode-container {
  background: rgba(31, 41, 55, 0.98);
}

.dark .qrcode-header {
  background: rgba(17, 24, 39, 0.8);
  border-color: #374151;
}

.dark .qrcode-box {
  background: rgba(17, 24, 39, 0.8);
  border-color: #374151;
}

.dark .qrcode-tip {
  color: #9ca3af;
}

/* 优化第三方登录图标在深色模式下的样式 */
.dark .github {
  color: #c9d1d9;
}

.dark .github:hover {
  background: #2f3542;
  color: #fff;
}

.dark .qq:hover,
.dark .wechat:hover,
.dark .gitee:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* 优化按钮样式 */
.submit-btn {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  border: none;
  outline: none;
  transition: all 0.2s ease;
}

.submit-btn:focus {
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.3);
}

.dark .submit-btn:focus {
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.4);
}

/* 优化输入框动画 */
.input-wrapper {
  position: relative;
  overflow: hidden;
}

/* 优化过渡动画 */
.login-wrapper,
.input-wrapper input,
.submit-btn,
.login-icon,
.form-switch a,
.forgot-password {
  transition: all 0.2s ease;
}

/* 优化加载动画 */
.loading-spinner {
  border-width: 2px;
  border-style: solid;
  border-color: rgba(255, 255, 255, 0.15);
  border-top-color: #fff;
}

.dark .loading-spinner {
  border-color: rgba(255, 255, 255, 0.1);
  border-top-color: #fff;
}

/* 其他样式保持不变 */
</style>
